﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TankPanel : MonoBehaviour {

    public Text nickText;
    public Image hpProgress;
    public float height = 3;

    protected Tank tank;
    protected Transform tankTrans;

    Vector3 followPoint;

    void Start () {
		
	}
    
    public void Init(Tank owenr,Data.Account acc)
    {
        this.tank = owenr;
        this.tankTrans = tank.transform ;

        SetHp(1);
        SetNick(acc.nickname);
    }

    private void LateUpdate()
    {
        followPoint = tankTrans.position + Vector3.up * height;

        followPoint = Camera.main.WorldToScreenPoint(followPoint);

        transform.position = followPoint;
    }

    public void SetHp(float percent)
    {
        hpProgress.fillAmount = percent;
    }

    public void SetNick(string name)
    {
        nickText.text = name;
    }
}
